package com.tiamo.traders.controller;

import com.tiamo.traders.entity.News;
import com.tiamo.traders.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/tiamo/news")
public class NewsController {
    @Autowired
    NewsService newsService;

    @RequestMapping("/newsAdd")
    public int add(News news) {
        return newsService.add(news);
    }

    @RequestMapping("/newsUpdate")
    public int update(News news) {
        return newsService.update(news);
    }

    @RequestMapping("/delete")
    public int delete(News news) {
        return newsService.delete(news);
    }

    @RequestMapping("/findAll")
    public List<News> findAll(News news) {
        news.setPageNo((news.getPageNo()-1)*news.getPageSize());
        List<News> newsList=newsService.findAll(news);
//        System.out.println(newsList);
        return newsList;
    }

    @RequestMapping("/findById")
    public News findById(News news) {
        return newsService.findById(news);
    }

    @RequestMapping("/getCount")
    public int getCount(News news) {
        return newsService.getCount(news);
    }
}
